@extends('newAdmin.layout.main')

@section('content')
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">文章管理</a>
            <a><cite>文章</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon" style="line-height:30px">ဂ 刷新</i>
        </a>
    </div>
    <div class="x-body">
        <div class="layui-row">
            <button class="layui-btn" onclick="x_admin_show('新增', '{{url("backstage/addArticle")}}')">
                新增
            </button>
        </div>
        {{--<xblock>--}}
        {{--<button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>--}}
        {{--<span class="x-right" style="line-height:40px">共有数据：88 条</span>--}}
        {{--</xblock>--}}
        <table class="layui-table">
            <thead>
            <tr>
                {{--<th>--}}
                {{--<div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>--}}
                {{--</th>--}}
                <th>ID</th>
                <th>所属主题</th>
                <th>文章标题</th>
                <th>是否置顶</th>
                <th>状态</th>
                <th>属于客户端</th>
                <th>操作</th>
            </thead>
            <tbody>
            @foreach($list as $article)
                <tr>
                    {{--<td>--}}
                    {{--<div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>--}}
                    {{--</td>--}}
                    <td>{{$article->id}}</td>
                    <td>{{$article->articleClassify->name}}</td>
                    <td>{{$article->title}}</td>
                    <td>{{$article->top_text}}</td>
                    <td>{{$article->release_text}}</td>
                    <td>{{$article->belong_to_text}}</td>
                    <td class="td-manage">
                        <a title="编辑" onclick="x_admin_show('编辑', '{{url("backstage/editArticle", ['id' => $article->id])}}')" href="javascript:;">
                            <i class="layui-icon font-24">&#xe642;</i>
                        </a>
                        <a title="删除" onclick="del(this, '{{$article->id}}')" href="javascript:;">
                            <i class="layui-icon font-24">&#xe640;</i>
                        </a>
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
        <div class="page">
            {{$list->links()}}
        </div>
    </div>
    <script>
        $(function  () {
            layui.use('form', function(){
                const form = layui.form;
                //监听提交
                form.on('submit(add)', function(){e
                    $.ajax({
                        url: '{{url("backstage/addTheme")}}',
                        type: 'POST',
                        dataType: 'json',
                        data: $('#add-theme').serialize(),
                        success: function (result) {
                            if (result.status === 0) {
                                layer.msg(result.msg);
                                location.href = '{{url("backstage/theme")}}';
                                return false;
                            }
                            layer.msg(result.msg);
                            return false;
                        },
                        error: function () {
                            layer.msg('增加失败，请重试！');
                            return false;
                        }
                    });
                    return false;
                });
            });
        })

        /*广告-删除*/
        function del(obj, id){
            layer.confirm('确认要删除吗？',function(){
                //发异步删除数据
                $.ajax({
                    url: '{{url("backstage/delArticle/")}}' + '/' + id,
                    type: 'get',
                    dataType: 'json',
                    data: {},
                    success: function (result) {
                        if (result.status === 0) {
                            $(obj).parents("tr").remove();
                            layer.msg('已删除!', {icon:1,time:1000});
                            location.href = '{{url("backstage/article")}}';
                            return false;
                        }
                        layer.msg(result.msg);
                        return false;
                    },
                    error: function () {
                        layer.msg('删除失败，请重试！');
                        return false;
                    }
                });
                return false;
            });
        }

        // function delAll (argument) {
        //     var data = tableCheck.getData();
        //     layer.confirm('确认要删除吗？'+data,function(index){
        //         //捉到所有被选中的，发异步进行删除
        //         layer.msg('删除成功', {icon: 1});
        //         $(".layui-form-checked").not('.header').parents('tr').remove();
        //     });
        // }
    </script>
@endsection
